/*
 * RandomSmallCover.cpp
 *
 *  Created on: 20 oct. 2011
 *      Author: gtempier
 */
#include <time.h>
#include <cstdlib>
#include "RandomSmallCover.h"

RandomSmallCover::RandomSmallCover(int nbVertex, int nbCover, float proba) : Graph()
{
	generateRandomSmallCover(nbVertex, nbCover, proba);
}

void
RandomSmallCover::generateRandomSmallCover(int nbVertex, int nbCover, float proba) {
	srand(time(NULL));
	vector<int> coverVertexes;

	//on cree k vertex couvrants
	for (int i = 0; i < nbVertex; ++i) {
		int vertex = addVertex();
		if (nbCover > 0) {
			coverVertexes.push_back(vertex);
			nbCover--;
		}
	}

	//on cree des arcs entre les sommets couvrants et les sommets non couvrants/couvrants
	for (int i = 0; i < coverVertexes.size(); i++) {

		for (int j = 0; j < _vertex_list.size(); j++) {
			if (coverVertexes[i] == j) continue;

			double r = rand()/(double)RAND_MAX;
			if(r < proba && !haveEdge(coverVertexes[i], j)) {
				addEdge(coverVertexes[i], j);
			}
		}
	}
}

